import time
import datetime
import sys
import os
#sys.path.append('C:/Project/PythonSpider')
#sys.path.append('D:/Project/PythonSpider')


from scrapy import cmdline
# cmdline.execute('scrapy crawl XueqiuSpider'.split())
# cmdline.execute("scrapy runspider Spider_Xueqiu.py".split())

filePath = os.getcwd()
runningTime = datetime.time(0, 0)
print("Spider Schedule Started")
while True:
    #print(filePath)
    now = datetime.datetime.now()
    today = now.date()

    continueTime = datetime.datetime.combine(today, runningTime)
    if now.time() > runningTime:
        continueTime = datetime.datetime.combine( (now + datetime.timedelta(days=1)).date(), runningTime )

    sleepSecond = (continueTime - now).total_seconds()
    print("Sleep Time", sleepSecond)
    time.sleep(sleepSecond)
    os.system("scrapy runspider " + "Spider_Xueqiu.py")
    time.sleep(10)